package com.briup.bookstore.web.controller;

import com.briup.bookstore.common.response.Result;
import com.briup.bookstore.domain.vo.BookDetailVO;
import com.briup.bookstore.domain.vo.BookVO;
import com.briup.bookstore.service.BookService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/book")
@RequiredArgsConstructor
public class BookController {

    private final BookService bookService;

    @GetMapping("/showBooks")
    public Result<?> showBooks() {
        List<BookVO> books = bookService.showBooks();
        return Result.success(books)
                .apply("展示图书列表成功");
    }

    @GetMapping("/findByCategory/{id}")
    public Result<?> findByCategory(@PathVariable Integer id) {
        List<BookVO> books = bookService.findByCategory(id);
        return Result.success(books)
                .apply("获取成功");
    }

    @GetMapping("/searchBook")
    public Result<?> searchBook(String query) {
        List<BookVO> books = bookService.searchBook(query);
        return Result.success(books)
                .apply("搜索图书成功");
    }

    @GetMapping("/{id}")
    public Result<BookDetailVO> findById(@PathVariable Integer id) {
        BookDetailVO detailVO = bookService.findById(id);
        return Result.success(detailVO)
                .apply("获取图书详情成功");
    }
}
